import React from 'react'
import { NavBar } from 'antd-mobile';
// import './index.scss'
import styles from './index.module.css'  //导入防止全局样式重叠的样式文件
import propTypes from 'prop-types'; //导入校验规则
import { withRouter } from 'react-router-dom'  //处理返回上一页失败功能组件
class NavHeader extends React.Component {
    render() {
        let defaultHandler = () => {
            this.props.history.go(-1)
        }
        return (
            <NavBar
                className={styles.navbar}
                mode="light"
                icon={<i className='iconfont icon-back' />}
                // 左侧按钮的点击事件
                onLeftClick={this.props.onleftClick || defaultHandler}
            > {this.props.children}</NavBar >
        )
    }
}

//校验规则
NavHeader.propTypes = {
    children: propTypes.string.isRequired,
    onleftClick: propTypes.func



}

// 通过withRouter 包装一层后，返回的还是一个组件，这个跟我们之前讲到的包装组件很类似
export default withRouter(NavHeader)
